package com.yfp.operation.controller;

import com.yfp.common.core.domain.R;
import com.yfp.common.core.utils.poi.ExcelUtil;
import com.yfp.operation.domain.vo.MachineDayData;
import com.yfp.operation.domain.vo.RegulateDataVO;
import com.yfp.operation.service.StatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/statistics")
@Tag(name = "数据统计")
public class StatisticsController {

    @Autowired
    private StatisticsService statisticsService;

    @Operation(summary = "数据统计", description = "数据统计管理页面使用")
    @GetMapping("/get")
    public R<RegulateDataVO> dataStatistics(@ApiParam(value = "设备id") @NotNull(message = "设备id不能为空") @RequestParam("machineId") String machineId) {

        RegulateDataVO dataStatistics = statisticsService.getDataStatistics(machineId);
        return R.ok(dataStatistics);

    }


    @Operation(summary = "数据统计", description = "数据统计")
    @GetMapping("/machineDayData")
    public void dataStatistics(HttpServletResponse response) {
        List<MachineDayData> dataStatistics = statisticsService.getMachineDayData();
        ExcelUtil<MachineDayData> util = new ExcelUtil<>(MachineDayData.class);
        util.exportExcel(response, dataStatistics, "数据统计");
    }

}
